import { defineStore } from 'pinia'
export const useTabsStore = defineStore('navtabs', {
  state: () => ({
    tabs: []
  }),
  actions: {
    initTab(tabs) {
      if (Array.isArray(tabs)) {
        this.tabs = tabs
      }
    },
    // 增
    addTab(tab) {
      const { path } = tab
      const flag = this.tabs.some((item) => item.path === path)
      if (flag) return
      this.tabs.push(tab)
    },
    // 删除一个
    delOne(path) {
      const index = this.tabs.findIndex((item) => item.path === path)
      index > -1 && this.tabs.splice(index, 1)
      return index > -1
    },
    //关闭所有 - 筛选出isAffix为true的成员
    delAll() {
      this.tabs = this.tabs.filter((item) => item.isAffix)
    },
    // 关闭其他
    delOthers(path) {
      this.tabs = this.tabs.filter((item) => item.isAffix || item.path === path)
    }
  }
})
